package com.yuyou.fn.cas;

import org.jasig.cas.client.configuration.BaseConfigurationStrategy;
import org.jasig.cas.client.configuration.ConfigurationKey;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.Filter;
import javax.servlet.FilterConfig;
import java.util.Properties;

public class SpringConfigurationStrategy extends BaseConfigurationStrategy {

    private  volatile Properties properties ;

    @Override
    protected String get(ConfigurationKey configurationKey) {
        return properties.getProperty("cas."+configurationKey.getName());
    }

    @Override
    public void init(FilterConfig filterConfig, Class<? extends Filter> filterClazz) {
        properties = (Properties) WebApplicationContextUtils.getWebApplicationContext(filterConfig.getServletContext()).getBean("applicationConfig") ;
        properties.put("cas.authenticationRedirectStrategyClass" ,"com.yuyou.fn.cas.CasRedirectStrategy");
        properties.put("cas.redirectAfterValidation" ,"false" );
    }
}
